<?php
	namespace app\api\controller;
	// use app\api\controller\Common;
	use think\Controller;
	/**
	* 
	*/
	class User extends Common{
		
		public function login() {
	        /*********** 接收参数  ***********/
	        $data = $this->params;
	        /*********** 检测用户名  ***********/
	        $user_name_type = $this->check_username($data['user_name']);
	        switch ($user_name_type) {
	        case 'phone':
	            $this->check_exist($data['user_name'], 'phone', 1);
	            $db_res = db('user')
	                ->field('user_id,user_name,user_phone,user_email,user_rtime,user_pwd')
	                ->where('user_phone', $data['user_name'])
	                ->find();
	            break;
	        case 'email':
	            $this->check_exist($data['user_name'], 'email', 1);
	            $db_res = db('user')
	                ->field('user_id,user_name,user_phone,user_email,user_rtime,user_pwd')
	                ->where('user_email', $data['user_name'])
	                ->find();
	            break;
	        }
	        if ($db_res['user_pwd'] !== $data['user_pwd']) {
	            $this->ret_msg(400, '用户名或者密码不正确!');
	        } else {
	            unset($db_res['user_pwd']); // 密码永不返回
	            $this->ret_msg(200, '登录成功!', $db_res);
	        }
	    }
	}